package com.example.yuejian21.nongfusanquan.yuejian21.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.activity.CoursedetailActivity;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubcoursebean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Couchcoursebean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Coursebean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Nongfusanquan on 2017-10-12.
 */

public class CouchcourseAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;

    private LayoutInflater mLayoutInflater;

    public CouchcourseAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_couchcourse, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Couchcoursebean entity = (Couchcoursebean) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.t_name.setText(entity.getPc_name());
        final String t_picture = "http://10.0.2.2/yuejian14/Public/Admin/trainpicture/"+entity.getPc_pic();
        //System.out.print("pic");
        if (!t_picture.equals("")) {
            Picasso.with(mContex).load(t_picture).into(viewHolder.t_picture);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Bundle bundle=new Bundle();
//
//                bundle.putString("t_name",entity.getT_name());
//                bundle.putString("t_info",entity.getT_info());
////                bundle.putInt("t_price",entity.getT_price());
//                bundle.putString("t_address",entity.getT_address());
//                bundle.putString("t_time",entity.getT_time());
//                bundle.putString("t_picture",entity.getT_picture());
//
////                bundle.putString("t_phone",entity.getT_phone());
//                Intent intent=new Intent(mContex, CoursedetailActivity.class);
//                intent.putExtras(bundle);
//                mContex.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView t_picture;
        TextView t_name;

        public ViewHolder(View itemView) {
            super(itemView);
            t_name = (TextView) itemView.findViewById(R.id.couchcourse_name);
            t_picture = (ImageView) itemView.findViewById(R.id.couchcourse_picture);

        }
    }
}

